package com.boco.pciv.controller;

import com.boco.pciv.core.controller.BaseMvcExceptionHandler;
import com.boco.pciv.core.exception.PcivException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by CC on 2017/9/12.
 */
@ControllerAdvice
public class PcivMvcGlobalExceptionHandler extends BaseMvcExceptionHandler {
    //logger
    private static final Logger logger = LoggerFactory.getLogger(PcivMvcGlobalExceptionHandler.class);


    @ExceptionHandler({ PcivException.class })
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ModelAndView pcivExpcetionHandler(HttpServletRequest req, PcivException e) {
        logger.warn("操作异常",e);
        ModelAndView m = new ModelAndView();
        m.addObject("url", req.getRequestURL());
        m.addObject("exception", e.getMessage());
        m.setViewName("error/500");
        return m;
    }
}
